import utils.StringUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 使用指定的重定向地址发送重定向响应到客户端
 */
@WebServlet("/main")
public class mainServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String token=req.getParameter("token");
        if(!StringUtils.hasLength(token) && "admin".equals(token)){
            resp.setContentType("text/html");
            resp.setCharacterEncoding("utf-8");
            resp.getWriter().println("欢迎您，系统管理员");
        }else {
            resp.sendRedirect("http://localhost:8080/first-servlet/login.html");
        }
    }
}
